angular.module("module.login",[])
    .config(['$stateProvider',function ($stateProvider) {
        $stateProvider
            .state('home.login',{
                url:"/login",
                templateUrl:"login/login.html",
                controller:'LoginController',
                controllerAs:'vm'
            })
    }])
    .controller('LoginController',[function () {
        var vm=this;
        $('#frm').submit(function(){
            var account = $.trim($('input[name=account]').val());
            var password = $.trim($('input[name=password]').val());
            var remember = $('input[name=remember]:checked') ? 1 : 0;
            if (!account) {
                $('.has-error').css('visibility','visible').html('用户名不能为空');
                return false;
            }
            if (!password) {
                $('.has-error').css('visibility','visible').html('密码不能为空');
                return false;
            }
            $('.has-error').css('visibility','hidden');
            $.post('ajaxLogin',{account:account, password:password, remember:remember}, function(res){
                try{res=JSON.parse(res)}catch(e){}
                if (!res.succeed){$('.has-error').css('visibility','visible').html(res.message); return false;}
                window.location.href='/goodsOrder';
            });
            return false;
        });
    }]);